package ca.compsci.opent.compiler.optimizer;

import ca.compsci.opent.compiler.node.AAndOpr;
import ca.compsci.opent.compiler.node.AOrOpr;
import ca.compsci.opent.compiler.semantics.Literal;
import ca.compsci.opent.compiler.semantics.Type;

public class BooleanEvaluator extends Evaluator<Boolean> {
	private boolean left, right;
	private Boolean result = null;
	
	public BooleanEvaluator(Literal l, Literal r) {
		left = (Boolean) l.getValue();
		right = (Boolean) r.getValue();
	}

	@Override
	public void caseAAndOpr(AAndOpr node) {
		result = Boolean.valueOf(left & right);
	}

	@Override
	public void caseAOrOpr(AOrOpr node) {
		result = Boolean.valueOf(left | right);
	}

	@Override
	public Boolean result() {
		return result;
	}

	@Override
	public Type resultantType() {
		return Type.Boolean;
	}
}
